from celery import Celery
from django.conf import settings
import sys
import os


BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(BASE_DIR, '../aijia_house_renting'))
os.environ['DJANGO_SETTINGS_MODULES'] = 'aijia_house_renting.dev'

app = Celery('aijia', broker='redis://127.0.0.1:6379/14', backend='redis://127.0.0.1:6379/15')

@app.task(bind=True, name='send_sms_code')
def send_sms_code(self, mobile, sms_code):
    from libs.yuntongxun.sms import CCP

    try:
        ccp = CCP()
        res = ccp.send_template_sms(mobile, [sms_code, 3], 1)
    except:
        res = -1

    if res == -1:
        self.retry(countdown=5, max_retries=3)
